package com.winsomely.leecode;

/**
 * 单词规律
 * 
 * @author liujiawei
 *
 */
public class WordPattern {

	public boolean wordPattern(String p, String s) {		
		String[] as = s.split(" ");
		if (p.length() != as.length) {
			return false;
		}
		if (p.length() == 1 && as.length == 1) {
			return true;
		}
		for (int i = 0; i < as.length - 1; i++) {
			for (int j = i + 1; j < as.length; j++) {
				if (as[i].equals(as[j]) != (p.charAt(i) == p.charAt(j))) {
					return false;
				}
			}
		}
		return true;
	}

	public static void main(String[] args) {
		WordPattern t = new WordPattern();
		String p ="a";
		String s ="dog";
		System.out.println(t.wordPattern(p, s));
	}

}
